home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c++
- Subject: Re: Inline function problem
- Date: 10 Jan 1996 21:17:03 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan10161703@g7240065.bridge.bst.bls.com>
- References: <4d10i5$bc3@newsroom.hitc.com>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: Chris Ruegger's message of 10 Jan 1996 18:29:25 GMT
-
- In article <4d10i5$bc3@newsroom.hitc.com> Chris Ruegger <cruegger@eos.hitc.com> writes:
-
- : I thought I was able to do the following but I am getting an
- : unresolved reference:
-
- : (Running SunOS 5.4)
-
- : // in file foo.H
- : class FOO {
- : public:
- : int x();
- : private:
- : int x_;
- : };
-
- : // in file foo.C:
- : #include <foo.H>
- : inline int FOO::x() {return x_;}
-
- This needs to be in the header file !!
-
- : // main.C
- : #include <foo.H>
- : #include <iostream.h>
- : int main(int argc, char *argv[])
- : {
- : FOO myfoo;
- : cout << myfoo.x() << endl;
- : }
-
- : When I try to link, I get:
-
- : Undefined first referenced
- : symbol in file
- : FOO::x(void) main.o
- : ld: fatal: Symbol referencing errors. No output written to main
-
- : }
-
- : Is this a compiler specific thing or illegal C++?
-
- This is illegal C++
-
- 7.1.2 Function specifiers
- ...
- 3 An inline function shall be defined in every transalation unit in which
- it is used ... If a function with external linkage is declared inline in one
- translation unit, it shall be declared in line in all translation units in
- which it appears.
-
- Putting the inline function in the header file will guarentee this.
-
- Regards
-
- -A.
- --
- | A.Champion |
-